package org.xxx.epms.models.epms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.xxx.epms.models.epms.model.AqiGrade;
import org.xxx.epms.models.epms.mapper.AqiGradeMapper;
import org.xxx.epms.models.epms.service.AqiGradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lb
 * @since 2024-06-08
 */
@Service
public class AqiGradeServiceImpl extends ServiceImpl<AqiGradeMapper, AqiGrade> implements AqiGradeService {

    @Autowired
    private AqiGradeMapper aqiGradeMapper;

    @Override
    public AqiGrade getAqiGradeByLevel(Integer level) {
        QueryWrapper<AqiGrade> wrapper = new QueryWrapper<>();
        wrapper.eq("aqi_level", level);
        return aqiGradeMapper.selectOne(wrapper);
    }
    @Override
    public Integer getAqiGradeByCoValue(Integer coValue) {
        if(coValue < 0){
            return 0;
        }
        Integer aqiLevel = aqiGradeMapper.getAqiGradeByCoValue(coValue);
        if (aqiLevel == null ) {
            return 6;
        }
        return aqiLevel;
    }

    @Override
    public Integer getAqiGradeBySo2Value(Integer so2Value) {
        if(so2Value < 0){
            return 0;
        }
        Integer aqiLevel = aqiGradeMapper.getAqiGradeBySo2Value(so2Value);
        if (aqiLevel == null ) {
            return 6;
        }
        return aqiLevel;
    }

    @Override
    public Integer getAqiGradeByPmValue(Integer pmValue) {
        if(pmValue < 0){
            return 0;
        }
        Integer aqiLevel = aqiGradeMapper.getAqiGradeByPmValue(pmValue);
        if (aqiLevel == null ) {
            return 6;
        }
        return aqiLevel;
    }
}
